import { cloudService } from './index'
import { IProduct, IQueryProduct } from '@/types/product.ts'

export const addProductApi = (product: IProduct): Promise<boolean> =>
  cloudService({
    url: '/home-api/product',
    method: 'post',
    data: product
  })

export const updateProductApi = (id: number, product: IProduct): Promise<boolean> =>
  cloudService({
    url: `/home-api/product/${id}`,
    method: 'put',
    data: product
  })

export const deleteProductApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/home-api/product/${id}`,
    method: 'delete'
  })

export const queryProductApi = (id: number): Promise<IProduct> =>
  cloudService({
    url: `/home-api/product/${id}`,
    method: 'get'
  })

export const queryProductListApi = (query: IQueryProduct): Promise<IProduct[]> =>
  cloudService({
    url: '/home-api/product',
    method: 'get',
    params: query
  })

export const queryProductCategoryApi = (): Promise<string[]> =>
  cloudService({
    url: '/home-api/product/category',
    method: 'get'
  })
